#include <iostream>  
using namespace std;  
  
void hanoiNonRecursive(int n, char from, char to, char aux) {  
    int i, j;  
    int state[10] = {0}; // state[i] represents the position of disk i  
    state[0] = from; // disk 0 is always on the start peg  
    for (i = 1; i <= n; i++) {  
        state[i] = from; // initialize all disks to the start peg  
    }  
    while (state[n] != to) { // while the top disk is not on the target peg, perform steps  
        for (i = n-1; i >= 1; i--) { // move smaller disks to the auxiliary peg or the target peg if they are already on the auxiliary peg or the target peg respectively  
            if (state[i] == from || state[i] == aux) {  
                state[i] = to; // move disk i to the target peg if it is on the start peg or the auxiliary peg  
                if (state[i+1] == from || state[i+1] == to) { // move disk i+1 to the auxiliary peg if it is on the start peg or the target peg  
                    state[i+1] = aux;  
                } else if (state[i+1] == aux) { // move disk i+1 to the target peg if it is already on the auxiliary peg  
                    state[i+1] = to;  
                } else { // if disk i+1 is already on the target peg, do nothing because we cannot move it anywhere else without violating the rules of Hanoi  
                    continue;  
                }  
            } else if (state[i] == to) { // if disk i is already on the target peg, do nothing because we cannot move it anywhere else without violating the rules of Hanoi  
                continue;  
            } else if (state[i] == aux) { // if disk i is already on the auxiliary peg, do nothing because we cannot move it anywhere else without violating the rules of Hanoi  
                continue;  
            } else { // if disk i is not on any peg, this should not happen because we should not be able to move any disk without moving smaller disks first according to the rules of Hanoi  
                cout << "Error: Disk " << i << " is not on any peg" << endl;  
                return;  
            }  
        }  
        for (j = n-1; j >= 0; j--) { // move smaller disks from the auxiliary peg to the start peg or the target peg if they are already on the auxiliary peg or the target peg respectively